package com.jetinno.utils;

import android.text.TextUtils;
import android.util.Log;

import com.jetinno.common.Log4jUtils;

public class LogUtils {

    public final static String order = "order";//订单相关
    public final static String xlog = "xlog";//普通操作日志
    public final static String net = "net";//网络相关
    public final static String operation = "operation";//用户操作
    public final static String mdb = "mdb";//mdb相关
    public final static String exception = "exception";//异常相关相关
    public final static String hb_machine = "hb_machine";//机器相关


    public static void init(boolean isDebug) {
        Log4jUtils.setDebug(isDebug);
        Log4jUtils.init();
    }

    public static void d(String tag, String logMsg) {
        Log.d(tag, logMsg);
    }

    public static void e(String tag, String logMsg) {
        Log.e(tag, logMsg);
    }

    // 写入到文件
    public static void d2File(String tag, String logMsg) {
        Log4jUtils.d(tag, logMsg);
    }

    public static void i2File(String tag, String logMsg) {
        Log4jUtils.i(tag, logMsg);
    }

    public static void e2File(String tag, String logMsg) {
        Log4jUtils.e(tag, logMsg);
    }

    public static void e2File(String tag, Throwable logMsg) {
        Log4jUtils.e(tag, logMsg);
    }

    public static void logXlog(String className, String logContent) {
        logToFile(xlog, className, logContent);
    }

    public static void logNet(String className, String logContent) {
        logToFile(net, className, logContent);
    }

    // 用户操作
    public static void logOperation(String className, String logContent) {
        logToFile(operation, className, logContent);
    }

    public static void logOrder(String className, String logContent) {
        logToFile(order, className, logContent);
    }

    ///保存日志并用Timber打印
    public static void logException(String className, Throwable throwable) {
        if (throwable != null) {
            throwable.printStackTrace();
            logToFile(exception, className, throwable.getMessage());
        }
    }

    ///保存日志并用Timber打印
    public static void logException(String className, String logContent) {
        if (!TextUtils.isEmpty(logContent)) {
            logToFile(exception, className, logContent);
        }
    }

    public static void logMachineState(String className, String send, String receive) {
        logToFile(hb_machine, className, String.format("%s->%s", send, receive));
    }


    /**
     * 写入mdb操作
     */
    public static void logMdb(String className, String logContent) {
        logToFile(mdb, className, logContent);
    }

    public static void logToFile(String logType, String className, String logContent) {
        String printToText = logType + " " + logContent;
        switch (logType) {
            case xlog:
                Log4jUtils.logXlog(className, printToText);
                break;
            case net:
                Log4jUtils.logNet(className, printToText);
                break;
            case operation:
                Log4jUtils.logOperation(className, printToText);
                break;
            case order:
                Log4jUtils.logOrder(className, printToText);
                break;
            case mdb:
                Log4jUtils.logMdb(className, printToText);
                break;
            case exception:
                Log4jUtils.logException(className, printToText);
                break;
            case hb_machine:
                Log4jUtils.logHeartBeat(className, printToText);
                break;
            default:
                break;
        }
    }


    /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>心跳包的日志>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/

}
